import SwiftUI

/*
 * 绘图示例
 */
class PaintExample: FCUIView{
    /*
    * 重绘背景的实现方法
    * view:视图
    * paint:绘图对象
    * clipRect:裁剪区域
    */
    func onPaint(view:FCView, paint:FCPaint, clipRect:FCRect) {
        onPaintDefault(view:view, paint:paint, clipRect:clipRect)
        if view.viewName == "TabPage"{
            paint.drawLine(color: "rgb(255,0,0)", width: 1, style: [], x1: 100, y1: 100, x2: 300, y2: 300)
            paint.drawLine(color: "rgb(255,0,255)", width: 1, style: [5,5], x1: 100, y1: 300, x2: 300, y2: 100)
        }else if view.viewName == "TabPage2"{
            paint.drawRect(color: "rgb(0,255,0)", width: 1, style: [], left: 100, top: 100, right: 200, bottom: 200)
            paint.fillRect(color: "rgb(0,255,255)", left: 250, top: 250, right: 350, bottom: 350)
        }else if view.viewName == "TabPage3"{
            paint.drawEllipse(color: "rgb(0,255,255)", width: 1, style: [], left: 100, top: 100, right: 200, bottom: 200)
            paint.fillEllipse(color: "rgb(255,0,255)", left: 250, top: 250, right: 350, bottom: 350)
        }else if view.viewName == "TabPage4"{
            paint.drawText(text: "FaceCat", color: "rgb(255,0,0)", font: "Default,30", x: 100, y: 100)
        }else if view.viewName == "TabPage5"{
            paint.beginPath()
            paint.addLine(x1: 100, y1: 100, x2: 150, y2: 120)
            paint.addLine(x1: 150, y1: 120, x2: 130, y2: 200)
            paint.addLine(x1: 130, y1: 200, x2: 200, y2: 200)
            paint.addLine(x1: 200, y1: 200, x2: 250, y2: 220)
            paint.drawPath(color: "rgb(255,0,0)", width: 1, style: [])
            paint.closePath()
        }else if view.viewName == "TabPage6"{
            paint.beginPath()
            paint.addLine(x1: 100, y1: 100, x2: 150, y2: 120)
            paint.addLine(x1: 150, y1: 120, x2: 200, y2: 200)
            paint.addLine(x1: 200, y1: 200, x2: 150, y2: 200)
            paint.fillPath(color: "rgb(0,0,255)")
            paint.closePath()
        }
    }
    
    /*
     * 初始化布局
     */
    override func onLoad(){
        let isInit = super.m_isInit;
        super.onLoad();
        if !isInit{
            m_paint.defaultUIStyle = "light"
            let width = Double(self.frame.size.width), height = Double(self.frame.size.height)
            renderFaceCat(name:"paintexample", paint: m_paint, size: FCSize(cx:width, cy:height))
            m_paint.addPaintEvent(callBack: onPaint)
        }
    }
}
